home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
menfram.exe
/
MENFRAME.DOC
< prev
next >
Wrap
Text File
|
1992-12-30
|
3KB
|
112 lines
MenFrame defines the new TV type TMenuFrame, which implements a sytem menu
for ordinary windows. If you click on the close icon of the window, you will
open a menu, that contains the items
Item Command
Zoom cmZoom
Move/Size cmResize
Close cmClose
Next Window cmNext
Each of these items simply sends a predefined TV command to it's owner.
The effect will be as you expect ( if you didn't redefine one of these
commands of course )
Using TMenuFrame is simple. You just have to write a new InitFrame procedure
for your windows class, that looks like:
procedure TMyWindow.InitFrame;
var
R : TRect;
begin
GetExtent(R);
frame:= new TMenuFrame(R);
end;
You may also exent the menu if you wish. TMenuFrame defines a procedure
AppendMenu(pM:PMenuItem).
Suppose you want to define two new items dummy1 and dummy2. Your InitFrame
procedure then could look like this
procedure TMyWindow.InitFrame;
var
R : TRect;
begin
GetExtent(R);
frame:= new TMenuFrame(R);
if frame<>Nil then
begin
PMenuFrame(frame)^.AppendMenu(
NewItem('Dummy2', 'F9', kbF9, cmDummy2, hcNoContext,
NewItem('Dummy1', 'Ctlr-F9', kbCtrlF9, cmDummy1, hcNoContext,
NewLine(
Nil))));
end
end;
As you can see in the example, the structure you want to append to the system
menu must be inserted in invers order.
Deleting items from the menu is possible too. You just have to use the DeleteMenu
Procedure. DeleteMenu wants a ShortInt as parameter, which represents the
position of the item within the menu. 0 is the first ( top ) item.
For example PMenuFrame(frame)^.DeleteMenu(1) would delete the second item in
the menu ( Move/Size by default ).
Unfortunatly i used some code from the Borland TV library source. Thus
i cannot supply you with the source of TMenuFrame. Following you find the
interface section of the unit:
Unit MenFrame;
Interface
uses Drivers, Objects, Views, Menus, App;
type
PMenuFrame = ^TMenuFrame;
TMenuFrame = Object(TFrame)
last : PMenuItem;
items : ShortInt;
constructor Init(var Bounds : TRect);
procedure HandleEvent(var Event: TEvent); virtual;
procedure AppendMenu(pM:PMenuItem);
procedure DeleteMenu(b : ShortInt);
end;
implementation
As usual .tpu is the real mode and .tpp the protected mode unit.
You will need Borland Pascal 7.0 to use these units.
There is no kind of copyright on the code. ( As a matter of fact, the code
is so simple, that according to the german laws i do not even have the right
to claim a copyright on it )
I wrote this code in order to demonstrate, that this kind of feature is easy
to implement in TV. ( This kind of system menu is standard for Visual Basic
for DOS forms and some friends argued, that it would be difficult to enhance
TV with such a feature ). Thus I have not tested the code extensively. If you
run into any problems I would be glad, if you would report the error to me.
My email address is horstmei.abg@sni.de, my compuserve account is 100012,3451.
Jens Horstmeier
Finkenstr. 6
DW-8901 Langweid am Lech
Germany